package com.coscoshipping.rams.demo.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coscoshipping.rams.demo.entity.AEncrypt;
import com.coscoshipping.rams.demo.mapper.AEncryptMapper;
import com.coscoshipping.rams.demo.pojo.dto.dict.AEncryptDTO;
import com.coscoshipping.rams.demo.pojo.vo.AEncryptVO;
import com.coscoshipping.rams.demo.service.IAEncryptService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhaoyin.yang
 * @since 2024-07-12
 */
@Service
public class AEncryptServiceImpl extends ServiceImpl<AEncryptMapper, AEncrypt> implements IAEncryptService {


    /**
     * @param id
     * @description 测试查询 普通参数 拦截器对结果对象进行解密
     * @return: com.coscoshipping.rams.demo.entity.AEncrypt
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @Override
    public AEncryptVO getAEncryptById(Integer id) {
        return Convert.convert(AEncryptVO.class, this.getById(id));
    }

    /**
     * @param aEncrypt
     * @description 测试插入 传参为对象，拦截器对含有加密注解的对象的属性 进行自动加密
     * @return: int
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @Override
    public void addAEncrypt(AEncryptDTO aEncrypt) {
        this.save(Convert.convert(AEncrypt.class, aEncrypt));
    }

    /**
     * @description 测试查询 查询结果为list 需要对list结果里的对象属性进行解密
     * @return: java.util.List<com.coscoshipping.rams.demo.entity.AEncrypt>
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @Override
    public List<AEncryptVO> getAllAEncrypts() {
        System.out.println("================> " + Thread.currentThread());
        return Convert.toList(AEncryptVO.class, this.list());
    }

    /**
     * @param mobile
     * @description 测试查询 普通参数加密
     * @return: java.util.List<com.coscoshipping.rams.demo.entity.AEncrypt>
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @Override
    public List<AEncryptVO> getAEncryptByPhone(String mobile) {
        return this.getBaseMapper().getAEncryptByPhone(mobile);
    }

    /**
     * @param encryptDTO
     * @description 测试查询 传参为对象 对象中的mobile参数需要拦截器进行加密才能查询
     * @return: java.util.List<com.coscoshipping.rams.demo.entity.AEncrypt>
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @Override
    public List<AEncryptVO> getAEncryptByAEncrypt(AEncryptDTO encryptDTO) {
        return this.getBaseMapper().getAEncryptByAEncrypt(encryptDTO);
    }

    /**
     * @param encrypts
     * @description 测试插入 对list进行加密
     * @return: int
     * @author zhaoyin.yang
     * @date 2024/4/3 16:16
     */
    @Override
    public void insertBatch(List<AEncryptDTO> encrypts) {
        this.saveBatch(Convert.toList(AEncrypt.class, encrypts));
    }

    /**
     * @param encryptList
     * @description 测试插入 使用@Param注解 对list进行加密
     * @return: int
     * @author zhaoyin.yang
     * @date 2024/4/3 16:16
     */
    @Override
    public void insertBatchByParam(List<AEncryptDTO> encryptList) {
        this.getBaseMapper().insertBatchByParam(encryptList);
    }

    /**
     * @param encrypt
     * @description 测试插入 普通参数加密，多个需要加密的字段
     * @return: int
     * @author zhaoyin.yang
     * @date 2024/4/3 16:16
     */
    @Override
    public void insertAEncrypt(AEncryptDTO encrypt) {
        this.getBaseMapper().insertAEncrypt(encrypt);
    }



    /**
     * @description 测试插入-普通参数加密
     * @param encrypt
     * @return: void
     * @author zhaoyin.yang
     * @date 2024/4/6 16:47
     */
    @Override
    public void insertAEncryptNormal(AEncryptDTO encrypt){
        this.getBaseMapper().insertAEncryptNormal(encrypt.getMobile(),
                encrypt.getIdentify(),
                encrypt.getBankcard(),
                encrypt.getEmail(),
                encrypt.getChineseName());
    }


    /**
     * @description lambdaUpdate测试
     * @return: void
     * @author zhaoyin.yang
     * @date 2024/4/11 17:01
     */
    @Override
    public void lambdaUpdateTest(){
        this.lambdaUpdate().set(AEncrypt::getEmail,"908486852@qq.com").eq(AEncrypt::getId,3).update();
    }
}
